﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
public partial class aspnet_admin_bock_Column_CX_Column_Temp_Edit : System.Web.UI.Page
{
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();



    /// <summary>
    /// 表名
    /// </summary>
    string Tab = "";

    /// <summary>
    /// 栏目名
    /// </summary>
    string Column_Name = "";

    string Rid = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Button2.Attributes.Add("onclick", "window.open('../../inc/UpFile.aspx?formname=aspnetForm&amp;editname=" + _Pic.ClientID.ToString() + "&amp;uppath=UpFile','','status=no,scrollbars=no,top=20,left=110,width=600,height=265')");
       if(!IsPostBack)
       {
           PageLandX();
        }
    }


    protected void PageLand()
    {
        try
        {
            Rid = int.Parse(Request.QueryString["id"].ToString().Trim()).ToString();
            Tab = Request.QueryString["Tab"].ToString().Trim();
            Column_Name = TextData.SqlataSet("select top 1 * from [CX_Column] where CX_CX_Column_Tab_Name='" + Tab + "'").Tables[0].Rows[0]["CX_Column_Name"].ToString();
            this.Title = "添加" + Column_Name + "的内容";
            Label1.Text = Column_Name;
            Label2.Text = Column_Name;
        }
        catch
        {
            TextData.Err("些页面不能直接访问");
            Response.End();
        }

    }

    /// <summary>
    /// 首次加载页面
    /// </summary>
    void PageLandX()
    {

        PageLand();

        DataTable Tdt = new DataTable();
        try
        {
            

            Tdt = TextData.SqlataSet("select top 1  * from [" + Tab + "] where [" + Tab + "_id]=" + Rid).Tables[0];
            Page.Title = "修改" + Label2.Text;

            _Name.Text = Tdt.Rows[0]["" + Tab + "_Name"].ToString();
            _LX.Value = Tdt.Rows[0]["" + Tab + "_LX"].ToString();
            _Pic.Text = Tdt.Rows[0]["" + Tab + "_Pic"].ToString();
            _Contont.Html = Tdt.Rows[0]["" + Tab + "_Contont"].ToString();
            _Explier.Text = Tdt.Rows[0]["" + Tab + "_Explier"].ToString();
            _CreatefileName.Value = Tdt.Rows[0]["" + Tab + "_CreatefileName"].ToString();
            _Sort.Text = Tdt.Rows[0]["" + Tab + "_Sort"].ToString();
            _Link.Text = Tdt.Rows[0]["" + Tab + "_Link"].ToString();
           


            //Tdt.Clear();
            Tdt.Dispose();


        }
        catch
        {
            Tdt = TextData.SqlataSet("select top 1  * from [" + Tab + "]").Tables[0];

            Page.Title = "修改" + Label2.Text;

            _Name.Text = Tdt.Rows[0]["" + Tab + "_Name"].ToString();
            _LX.Value = Tdt.Rows[0]["" + Tab + "_LX"].ToString();
            _Pic.Text = Tdt.Rows[0]["" + Tab + "_Pic"].ToString();
            _Contont.Html = Tdt.Rows[0]["" + Tab + "_Contont"].ToString();
            _Explier.Text = Tdt.Rows[0]["" + Tab + "_Explier"].ToString();
            _CreatefileName.Value = Tdt.Rows[0]["" + Tab + "_CreatefileName"].ToString();
            _Sort.Text = Tdt.Rows[0]["" + Tab + "_Sort"].ToString();
            _Link.Text = Tdt.Rows[0]["" + Tab + "_Link"].ToString();

            //Tdt.Clear();
            Tdt.Dispose();
        }

    }
    

    /// <summary>
    /// 保存数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {

        PageLand();//得到应该有的参数

        if (int.Parse(_Sort.Text.Trim()) <= 99999 && _Name.Text.Trim() != ""&&Rid!="")
        {
            string sql = "";
            sql += "Update  [" + Tab + "]  Set   ";

            sql += " ";

            sql += "[" + Tab + "_Name]='" + _Name.Text.Trim() + "',[" + Tab + "_Contont]='" + _Contont.Html.Trim().Replace("'", "") + "',[" + Tab + "_PublicTime]='" + DateTime.Now.ToString() + "',[" + Tab + "_Pic]='" + _Pic.Text.Replace("'", "").Trim() + "',[" + Tab + "_Explier]='" + _Explier.Text.Trim() + "',[" + Tab + "_Sort]=" + _Sort.Text.Trim() + ",[" + Tab + "_CreatefileName]='" + _CreatefileName.Value.Trim() + "',[" + Tab + "_Link]='" + _Link.Text.Trim() + "',[" + Tab + "_LX]=" + _LX.Value.Trim() + "";

            sql += " where [" + Tab + "_id]="+Rid;

            TextData.SqlDataSave(sql);
            // Response.Write(sql);

            tt.Text = "修改 " + _Name.Text + " 成功";
           // _Name.Text = "";
        }
        else
        {
            tt.Text = "标题为空或其它内容为空 或存在同名标题";
        }

    }

    public String IsShowElement()
    {
        string scripttext = "";
        // Pic 显示小图片
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Pic"].ToString()))
            {
                scripttext += "document.getElementById(\"Pic\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"Pic\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"Pic\").style.display='none';\r\n";
        }

        // Cont 显示内容
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Cont"].ToString()))
            {
                scripttext += "document.getElementById(\"Cont\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"Cont\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"Cont\").style.display='none';\r\n";
        }

        // Expiler 说明
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Expiler"].ToString()))
            {
                scripttext += "document.getElementById(\"Expiler\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"Expiler\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"Expiler\").style.display='none';\r\n";
        }


        // Crtfile 生成文件名 
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Crtfile"].ToString()))
            {
                scripttext += "document.getElementById(\"Crtfile\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"Crtfile\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"Crtfile\").style.display='none';\r\n";
        }

        // Sort 排序
        try
        {
            if (Convert.ToBoolean(Request.QueryString["Sort"].ToString()))
            {
                scripttext += "document.getElementById(\"Sort\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"Sort\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"Sort\").style.display='none';\r\n";
        }

        // ShowLx 显示类型 
        try
        {
            if (Convert.ToBoolean(Request.QueryString["ShowLx"].ToString()))
            {
                scripttext += "document.getElementById(\"ShowLx\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"ShowLx\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"ShowLx\").style.display='none';\r\n";
        }
        // linkxx 链接地址
        try
        {
            if (Convert.ToBoolean(Request.QueryString["linkxx"].ToString()))
            {
                scripttext += "document.getElementById(\"linkxx\").style.display='';\r\n";
            }
            else
            {
                scripttext += "document.getElementById(\"linkxx\").style.display='none';\r\n";
            }
        }
        catch
        {
            scripttext += "document.getElementById(\"linkxx\").style.display='none';\r\n";
        }

        return scripttext;
    }
}
